//
//  I_Gym.m
//  YunDongAdmin
//
//  Created by lqq on 2018/9/5.
//  Copyright © 2018年 cloudfighting.com. All rights reserved.
//

#import "I_Gym.h"

@implementation I_Gym
/**
 请求门店列表
 */
+ (NetworkTask *)requestGymListOnSuccess:(void(^)(NSMutableArray *gymList))successBlock failure:(ErrorBlock)failureBlock
{
    
    return [NET POST:@"/gym-coach-api/gym/1.0.0/listGym" parameters:@{@"currentPage":@(1),@"pageSize":@(100)} criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        NSMutableArray *list = [M_Gym arrayOfModelsFromDictionaries:SAFE_VALUE_FOR_KEY(resultObject, @"data") error:nil];
        if (successBlock) {
            successBlock(list);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}




/**
 搜索健身房
 */
+ (NetworkTask *)searchGymByAddress:(NSString *)address
                            gymName:(NSString *)gymName
                               city:(NSString *)city
                           latitude:(CGFloat)latitude
                          longitude:(CGFloat)longitude
                            success:(void(^)(NSArray *list))successBlock failure:(ErrorBlock)failureBlock
{
    NSString *path;
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:@(latitude) forKey:@"gymLocationLatitude"];
    [params setObject:@(longitude) forKey:@"gymLocationLongitude"];
    [params setObject:SAFE_NIL_STRING(city) forKey:@"gymCity"];
    if (address.length > 0) {
        path = @"/gym-coach-api/gym/1.0.0/getGymAddressByAddress";
        [params safeSetObject:address forKey:@"gymAddress"];
    } else {
        path = @"/gym-coach-api/gym/1.0.0/getGymAddressByName";
        [params safeSetObject:gymName forKey:@"gymName"];
    }
    
    return [NET POST:path parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        NSArray *list = [M_Gym arrayOfModelsFromDictionaries:SAFE_VALUE_FOR_KEY(resultObject, @"data") error:nil];
        if (successBlock) {
            successBlock(list);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}


/**
 管理员创建健身房
 */
+ (NetworkTask *)editGymByAdmin:(M_Gym *)gym success:(void(^)(void))successBlock failure:(ErrorBlock)failureBlock
{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[gym toDictionary]];
    NSString *path = nil;
    if (gym.gymId) {
        path = @"/gym-coach-api/gym/1.0.0/editGym";
    } else {
        path = @"/gym-coach-api/gym/1.0.0/createGym";
    }
    return [NET POST:path parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            successBlock();
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}

/**
 品牌和健身房信息设置
 */
+ (NetworkTask *)creatBrandAndGymWithBrandName:(NSString *)brandName
                                  BrandCreator:(NSString *)brandCreator
                                           gym:(M_Gym *)gym
                                       success:(void(^)(void))successBlock
                                       failure:(ErrorBlock)failureBlock
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:[gym toDictionary]];
    [params safeSetObject:brandName forKey:@"brandName"];
    [params safeSetObject:brandCreator forKey:@"brandCreator"];

    return [NET POST:@"/gym-coach-api/admin/1.0.0/createBrandAndGym" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            successBlock();
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}
@end
